If

Conditionally runs a block of statements based on the value of an expression (True or False). If the condition is True, statements in the If block run. If the condition is False, statements in the If block are skipped and the script continues with the first statement outside of the block.

You can use the Else and ElseIf statements to run an alternate blocks of statements when the If condition is False.

Syntax

If Condition Then

[Statements]

[ElseIf Condition-n Then

[ElseIfStatements]]

[Else

[ElseStatements]]

End If

Tip: You can use a single line format for short, simple If statements.

Arguments

Argument Description
Condition Numeric or string expression that evaluates to True or False. For example, a > b, a < b, a = b, or a <> b. Null conditions are treated as False.
Statements One or more statements to run if Condition is True.

Keyword View notes

The condition to evaluate is displayed in the Information column.

Example

currentHour = Hour(Now())

Print("Time of day: ")

If (6 <= currentHour) and (currentHour < 12) Then

PrintLn("morning")

ElseIf (12 <= currentHour) and (currentHour < 18) Then

PrintLn("afternoon")

ElseIf (18 <= currentHour) and (currentHour < 24) Then

PrintLn("evening")

Else

PrintLn("night")

End If